package cn.kgc.liverservice.service;

import cn.kgc.bean.Liverorder;
import cn.kgc.myhousemapper.mapper.LiverorderMapper;
import cn.kgc.service.LiverOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Component
public class LiverOrderServiceImpl implements LiverOrderService {
    @Resource
    LiverorderMapper liverorderMapper;
    @Override
    public PageInfo<Liverorder> selectLiverOrders(Integer pageNum, Integer paegSize, Integer houseid, Date startTime, Date endTime, String orderNo, String liverName) {
        PageHelper.startPage(pageNum,paegSize);
        PageHelper.orderBy("date desc");
/*        LiverorderExample liverorderExample=new LiverorderExample();
        LiverorderExample.Criteria criteria = liverorderExample.createCriteria();*/
        QueryWrapper<Liverorder> queryWrapper=new QueryWrapper<>();
        if (houseid!=null&&houseid!=0){
            queryWrapper.eq("houseid",houseid);
        }
        if (startTime!=null&&!startTime.toString().equals("Mon Jun 06 00:00:00 CDT 1988")&&endTime!=null&&!endTime.toString().equals("Mon Jun 06 00:00:00 CDT 1988")){
            queryWrapper.between("date",startTime,endTime);
        }
        if (orderNo!=null&&!orderNo.equals("")){
            queryWrapper.eq("orderno",orderNo);
        }
        if (liverName!=null&&!liverName.equals("")){
            queryWrapper.like("username",liverName);
        }
        List<Liverorder> liverorders = liverorderMapper.selectList(queryWrapper);
        PageInfo<Liverorder> pageInfo=new PageInfo<>(liverorders);
        return pageInfo;
    }

    @Override
    public int deleteLiverOrderById(Integer id) {
       return liverorderMapper.deleteById(id);
    }

    @Override
    public int update(Liverorder liverorderr) {
        return liverorderMapper.updateById(liverorderr);
    }
}
